package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.*;
import com.ra.service.IPhotoAlbumService;
import com.ra.service.IPhotoService;
import com.ra.service.UploadService;
import com.ra.service.impl.PhotoAlbumServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 照片 前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "照片模块")
public class PhotoController {

    @Autowired
    private IPhotoAlbumService photoAlbumService;
    @Autowired
    private IPhotoService photoService;
    //文件上传策略
    @Autowired
    private UploadService uploadService;

    //admin/photos
    @ApiOperation(value = "根据相册id获取照片列表")
    @GetMapping("/admin/photos")
    public RespBean<RespPageBean<PhotoAdminDTO>> listPhotos(ConditionDTO conditionDTO) {
        return RespBean.success(photoService.listPhotos(conditionDTO));
    }

    @ApiOperation(value = "上传照片")
    @ApiImplicitParam(name = "file", value = "照片", required = true, dataType = "MultipartFile")
    @PostMapping("/admin/photos/upload")
    public RespBean<String> savePhotoAlbumCover(MultipartFile file) {
        return RespBean.success(uploadService.uploadFile(file, "photos/"));
    }

    @ApiOperation(value = "更新照片信息")
    @PutMapping("/admin/photos")
    public RespBean<?> updatePhoto(@Valid @RequestBody PhotoInfoDTO photoInfoDTO) {
        photoService.updatePhoto(photoInfoDTO);
        return RespBean.success();
    }


    @ApiOperation(value = "保存照片")
    @PostMapping("/admin/photos")
    public RespBean<?> savePhotos(@Valid @RequestBody PhotoDTO photoDTO) {
        photoService.savePhotos(photoDTO);
        return RespBean.success();
    }


    @ApiOperation(value = "移动照片相册")
    @PutMapping("/admin/photos/album")
    public RespBean<?> updatePhotosAlbum(@Valid @RequestBody PhotoDTO photoDTO) {
        photoService.updatePhotosAlbum(photoDTO);
        return RespBean.success();
    }


    @ApiOperation(value = "更新照片删除状态")
    @PutMapping("/admin/photos/delete")
    public RespBean<?> updatePhotoDelete(@Valid @RequestBody DeleteDTO deleteDTO) {
        photoService.updatePhotoDelete(deleteDTO);
        return RespBean.success();
    }


    @ApiOperation(value = "删除照片")
    @DeleteMapping("/admin/photos")
    public RespBean<?> deletePhotos(@RequestBody List<Integer> photoIds) {
        photoService.deletePhotos(photoIds);
        return RespBean.success();
    }

    @ApiOperation(value = "根据相册id查看照片列表")
    @GetMapping("/albums/{albumId}/photos")
    public RespBean<SeePhoto> listPhotosByAlbumId(@PathVariable("albumId") Integer albumId) {
        return RespBean.success(photoService.listPhotosByAlbumId(albumId));
    }



}

